package com.jrx.anytxn.customer.service;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.customer.dto.coupon.RightsExchangeLogRes;
import com.jrx.anytxn.customer.entity.TlRightsExchangeLog;

import java.util.List;

/**
 * ClassName IRightsExchangeLogService
 *
 * @author lujianyou
 * @version 1.0
 * @description 权益资格兑换接口
 * @date 2021/6/14 11:28
 **/
public interface IRightsExchangeLogService {

    void update(TlRightsExchangeLog tlRightsExchangeLog);

    /**
     * 保存
     * @param tlRightsExchangeLog
     * @return
     */
    int save(TlRightsExchangeLog tlRightsExchangeLog);

    /**
     *  获取客户权益资格兑换流水表
     * @param userId
     * @param tenantId
     * @param channel
     * @return
     * @throws TxnBizException
     */
    List<RightsExchangeLogRes> listByUserIdAndTenantIdAndChannel(String userId, String tenantId, String channel) throws TxnBizException;

    /**
     * 获取权益兑换明细
     * @param tenantId
     * @param orderState
     * @param channel
     * @return
     */
    List<TlRightsExchangeLog> selectByTenantIdAndOrderStateAndChannel(String tenantId, String orderState, String channel);

    /**
     * 更新权益兑换明细表
     * @param tenantId
     * @param sceneOrderId
     * @param channel
     * @param customerId
     * @return
     */
    int updateByCustomerIdAndSceneOrderId(String tenantId, String sceneOrderId, String channel,String customerId);

    /**
     * 批量插入
     * @param exchangeLogList
     * @return
     */
    int insertBatch(List<TlRightsExchangeLog> exchangeLogList);

    /**
     * 根据租户号、充值账号、被推荐人customerId、活动id 查询记录
     * 只允许batch调用
     * @param tenantId
     * @param chargeAccount
     * @param recommended
     * @param activityId
     * @return
     */
    List<TlRightsExchangeLog> listByChargeAccountAndRecommendedAndActivityId(String tenantId,String chargeAccount,
                                                                             String recommended,String activityId);

    List<TlRightsExchangeLog> listByChargeAccountAndRecommendedAndActivityIdAndTenantId(String tenantId,String chargeAccount,
                                                                             String recommended,String activityId);

    /**
     * 根基客户号、租户号、渠道 查询记录
     * @param customerId
     * @param tenantId
     * @param channel
     * @return
     */
    List<TlRightsExchangeLog> listByCustomerIdAndTenantIdAndChannel(String customerId, String tenantId, String channel);

    /**
     * 根据租户号、客户手机号、被推荐人customerId 查询记录
     * 只允许batch调用
     *
     * @param tenantId
     * @param customerPhone
     * @param recommended
     * @return
     */
    List<TlRightsExchangeLog> listByCustomerPhoneAndRecommended(String tenantId, String customerPhone, String recommended);

    /**
     * 根据客户编号，获取最新的若干条兑换记录
     * @param customerId
     * @param tenantId
     * @param channel
     * @param latestRows
     * @return
     */
    List<TlRightsExchangeLog> listLatestLogsByCustomer(String customerId, String tenantId, String channel, int latestRows);

    /**
     * 根据客户信息，查询最新的一条兑换记录
     * @param customerId
     * @param tenantId
     * @param channel
     * @return
     */
    TlRightsExchangeLog findLatestLogByCustomer(String customerId, String tenantId, String channel);

    /**
     * 根据id和客户信息，查询记录
     * @param id
     * @param customerId
     * @param tenantId
     * @param channel
     * @return
     */
    TlRightsExchangeLog findByIdAndCustomer(Long id, String customerId, String tenantId, String channel);

    /**
     * 根据场景订单id以及平台订单id查询订单
     * 场景订单id:scene_order_id
     * 平台订单id：coupon_system_order_id
     *
     * 在卡券系统中，scene_order_id为时间处理后的信息，coupon_system_order_id为卡券明细表中的id
     * @param tenantId
     * @param customerId
     * @param sceneOrderId
     * @param platOrderId
     * @return
     */
    TlRightsExchangeLog findBySceneOrderIdAndPlatOrderId(String tenantId, String customerId, String sceneOrderId, String platOrderId);

}
